'''
coding:utf-8
:writingtime: 2022-6-27
:author: wanjun
:reference: Information measures for q‐rung orthopair fuzzy sets
:doi: 10.1002/int.22115
:examiner: 
'''


class GetSimilarity:
    def __init__(self, IVQ1, IVQ2, q=3):
        '''

        :param IVQ1:
        :param IVQ2:
        :param q:
        '''
        self.IVQ1 = IVQ1
        self.IVQ2 = IVQ2
        self.q = q

    def getSimilarity(self):
        """

        :return:
        """
        q = self.q
        value1 = (min(self.IVQ1[0][0] ** q, self.IVQ2[0][0] ** q) + min(self.IVQ1[0][1] ** q,
                                                                        self.IVQ2[0][1] ** q) + min(
            (1 - self.IVQ1[1][0] ** q), (1 - self.IVQ2[1][0] ** q)) + min((1 - self.IVQ1[1][1] ** q),
                                                                          (1 - self.IVQ2[1][1] ** q)))
        value2 = (max(self.IVQ1[0][0] ** q, self.IVQ2[0][0] ** q) + max(self.IVQ1[0][1] ** q,
                                                                        self.IVQ2[0][1] ** q) + max(
            (1 - self.IVQ1[1][0] ** q), (1 - self.IVQ2[1][0] ** q)) + max((1 - self.IVQ1[1][1] ** q),
                                                                          (1 - self.IVQ2[1][1] ** q)))
        return value1/value2


def getSimilarity(a_list, b_list, q=3):
    if len(a_list) != len(b_list):
        print('两个集合论域错误')
    length = len(a_list)
    sum1 = 0;
    sum2 = 0
    for i in range(length):
        value1 = (min(a_list[i][0][0] ** q, b_list[i][0][0] ** q) + min(a_list[i][0][1] ** q, b_list[i][0][1] ** q) +
                  min((1 - a_list[i][1][0] ** q), (1 - b_list[i][1][0] ** q)) + min((1 - a_list[i][1][1] ** q),
                                                                                    (1 - b_list[i][1][1] ** q)))
        value2 = (max(a_list[i][0][0] ** q, b_list[i][0][0] ** q) + max(a_list[i][0][1] ** q, b_list[i][0][1] ** q) +
                  max((1 - a_list[i][1][0] ** q), (1 - b_list[i][1][0] ** q)) + max((1 - a_list[i][1][1] ** q),
                                                                                    (1 - b_list[i][1][1] ** q)))
        sum1 += value1
        sum2 += value2
    final_value = sum1 / sum2
    return final_value


if __name__ == '__main__':
    print(getSimilarity([[[0.3509, 0.3509], [0.3509, 0.3509]]], [[[0.4009, 0.4009], [0.4009, 0.4009]]], 3))
